package Operator;
import Billing.Billing;
import Billing.CallOperation;
import Billing.PhoneOperation;
import Billing.SmsOperation;

public abstract class PriceList {

	public int priceListUsers = 0;
	
	protected double regularCallCost;
	protected double playCallCost;
	protected double insideCallCost;
	
	protected double regularSmsCost;
	protected double insideSmsCost;
	
	protected String operatorName;
	
	public PriceList(String name)
	{
		operatorName = name;
	}
	
	/**
	 * Gives current rates.
	 * @return	Table consisting of 5 costs: regular call, play call, inside call, 
	 * 			regular sms and inside sms.
	 */
	public double [] getPrices()
	{
		double [] prices = new double[5];
		prices[0] = regularCallCost;
		prices[1] = playCallCost;
		prices[2] = insideCallCost;
		prices[3] = regularSmsCost;
		prices[4] = insideSmsCost;
		
		return prices;
	}
	
	public Double computeCost(Billing bill)
	{
		double sum = 0.0;
		
		for (PhoneOperation operation: bill.getOperations()) 
		{
			if (operation instanceof SmsOperation)
			{
				if (operation.getOperator().contains(operatorName))
				{
					sum += insideSmsCost;
					continue;
				}
				else{
					sum += regularSmsCost;
					continue;
				}
			}
			
			CallOperation co = (CallOperation) operation;

			if (operation.getOperator().contains("play"))
			{
				sum += playCallCost * java.lang.Math.ceil( co.getTimeOfCall() ) / 60.0;
			}
			else if (operation.getOperator().contains(operatorName))
				sum += insideCallCost * java.lang.Math.ceil( co.getTimeOfCall() ) / 60.0;
			else 
				sum += regularCallCost * java.lang.Math.ceil( co.getTimeOfCall() ) / 60.0;
		}
		
		return sum;
	}
}
